<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ leftCount }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          @click="selectFn('all')"
          :class="{ selected: selectType === 'all' }"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          @click="selectFn('active')"
          :class="{ selected: selectType === 'active' }"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="selectFn('complete')"
          :class="{ selected: selectType === 'complete' }"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button v-show="isShow" class="clear-completed">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    arr: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      // 定义tab栏切换 动态样式 对比
      selectType: "all",
    };
  },
  computed: {
    // 计算未完成数量
    leftCount() {
      return this.arr.filter((item) => !item.isDone).length;
    },
    // 计算未完成
    isShow() {
      return this.arr.some((item) => item.isDone);
    },
  },
  methods: {
    selectFn(type) {
      // 样式传参 对应显示高亮
      this.selectType = type;
      // 属性值传参做数据筛选判断
      this.$emit("changeType", type);
    },
  },
};
</script>
